<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Dragon Baby System</title>
		<%@include file="/commons/head.jsp"%>
		<script type="text/javascript">
		$(function() {
			$("#dialog:ui-dialog").dialog("destroy" );
			$("#dialog-form").dialog({
				autoOpen: false,
				height: 300,
				width: 350,
				modal: true,
				buttons: {
					"Save": function() {
						$.ajax({
							url:"${ctx}/product/product!addStr.do",
							data:"id=" + $("#proId").val() + "&str=" + $("#comm").val() + "&dialogType=" + $("#dialogType").val(),
							dataType:"text",
							success: function(text) {
								$("#comm").val("");
								$("#dialog-form").dialog( "close" );
						}});
					},
					Cancel: function() {
						$("#comm").val("");
						$("#dialog-form").dialog( "close" );
					}
				}
			});
			
			$("#dialog-price").dialog({
				autoOpen: false,
				height: 300,
				width: 350,
				modal: true,
				buttons: {
					"Save": function() {
						$.ajax({
							url:"${ctx}/product/product!addPrice.do",
							data:"id=" + $("#proId").val() + "&priceLog.price=" + $("#price").val() + "&priceLog.compId=" + $("#compId").val() + "&priceLog.priceType=" + $("input:[name=prictTypes]:radio:checked").val() + "&priceLog.descs=" + $("#priceDescs").val(),
							dataType:"text",
							success: function(text) {
								$("#price").val();
								$("#dialog-price").dialog( "close" );
						}});
					},
					Cancel: function() {
						$("#comm").val("");
						$("#dialog-price").dialog( "close" );
					}
				}
			});
			
			$("a[name = create-tags]").click(function() {
				$("#proId").val($(this).attr("value"));
				$("#dialogType").val("tags");
				loadStr();
			});
			$("a[name = create-comment]").click(function() {
				$("#proId").val($(this).attr("value"));
				$("#dialogType").val("comment");
				loadStr();
			});
		});
		
		function loadStr() {
			$.ajax({
				url:"${ctx}/product/product!getStr.do",
				data:"id=" + $("#proId").attr("value") + "&dialogType=" + $("#dialogType").val(),
				dataType:"text",
				success: function(text) {
					$("#comm").val(text);
			}});
			$( "#dialog-form" ).dialog( "open");
		}
		</script>
	</head>
	<body>
		<div class="wrapper">
			<%@include file="/commons/header.jsp" %>
			<div class="content">
				<%@include file="/commons/menu.jsp" %>
				<div class="primary">
					<h1>产品管理</h1>
					<div id="dialog-form" title="增加信息" >
						<input id="proId" type="hidden" value=""/>
						<input id="dialogType" type="hidden" value=""/>
						<textarea id="comm" style="width:300px;height:170px;"></textarea>
					</div>
					<ul id="dialog-price" title="增加价格" >
						<dt style="float: left;">公司：</dt>
						<dd>
							<s:select theme="simple" key="compId" list="companys" listKey="id" listValue="cnName" />
						</dd>							
						<dt style="float: left;">类型：</dt>
						<dd>询价<input type="radio" name="prictTypes" value="CP"/>报价<input type="radio" name="prictTypes" value="SP"/></dd>
						<dt style="float: left;">价格：</dt>
						<dd><input type="text" id="price" style="width:250px;" name="price"/></dd>
						<dt>说明</dt>
						<textarea id="priceDescs" style="width:300px;height:80px;"></textarea>
					</ul>
					<table cellspacing="0" id="ListTable">
						<caption>产品列表</caption>
						<thead>
							<tr>
								<th scope="col">产品</th>
								<th scope="col">名称</th>
								<th scope="col">英文名</th>
								<th scope="col">加入时间</th>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="page.result">
								<tr>
									<td>
										<div style="float:left;margin:3px;">${ref}<br/><img src='${ctx}/atta/atta!img.do?id=${logo.id}' /></div>
										<div style="float:left;margin:16px 3px 3px 3px;width:80px">
										<a style="float:left;" href="#" title="View" class="ui-icon ui-icon-search">View</a>
										<a style="float:left;" href="javascript:$('#proId').val('${id}');$('#dialog-price').dialog('open');" title="Price" class="ui-icon ui-icon-note">Price</a>
										<a style="float:left;" href="product!input.do?id=${id}" title="Modify" class="ui-icon ui-icon-wrench">Modify</a>
										<a style="float:left;" href="#" name="create-comment" type="comment" value="${id}" title="Comment" class="ui-icon ui-icon-comment">Comment</a>
										<a style="float:left;" href="#" name="create-tags" type="tag" value="${id}" title="Tags" class="ui-icon ui-icon-tag">Tag</a>
										<a style="float:left;" href="product!delete.do?id=${id}" title="Delete" class="ui-icon ui-icon-trash">Delete</a>
										</div>
									</td>
									<td>${name}</td>
									<td>${enName}</td>
									<td><s:date name="createDate" format="yyyy-MM-dd" /></td>
								</tr>
							</s:iterator>						
						</tbody>
						<tfoot>
							<tr>
								<td align="left">
									<a style="float:left;" title="Add" href="product!input.do" class="ui-icon ui-icon-document">Add</a>
								</td>
								<td colspan="4" align="right">
								<ui:page page="${page}" pageNum="10" />
							</td></tr>
						</tfoot>
					</table>
				</div>
			</div>
			<%@include file="/commons/footer.jsp" %>
		</div>
	</body>
</html>
